// Lang_35 [primitive implicit casts].nova // The application class. class PrimitiveImplicitCastsApp { // Application class's "main" function. public static void main( String[] args ) { byte b = 128; short s = 128; int i; // Implicitly cast the result to an "int" type. // NOTE: The expected result here is zero because of 8-bit "byte" overflow. i = b + b; Stream.writeLine( Integer.toString( i ) ); // Explicitly cast the first operand to an "int" type. // Implicitly cast the second operand to an "int" type. // NOTE: This prevents the above 8-bit "byte" overflow. i = (int)b + b; Stream.writeLine( Integer.toString( i ) ); // Explicitly cast the second operand to an "int" type. // Implicitly cast the first operand to an "int" type. // NOTE: This also prevents the above 8-bit "byte" overflow. i = b + (int)b; Stream.writeLine( Integer.toString( i ) ); // Implicitly cast the left operand to a "short" type. // Then implicitly cast the result to an "int" type. i = b + s; Stream.writeLine( Integer.toString( i ) ); // Implicitly cast the right operand to a "short" type. // Then implicitly cast the result to an "int" type. i = s + b; Stream.writeLine( Integer.toString( i ) ); } }